import {WeaSearchGroup, WeaFormItem} from 'ecCom';
import {WeaSwitch} from 'comsMobx';
import {toJS} from 'mobx';

export const getSearchs = (form, conditioninfo) => {
  const {isFormInit} = form;
  let group = [];
  if (isFormInit) {
    let formParams = form.getFormParams(); // 获取表单的值
    conditioninfo = toJS(conditioninfo);
    isFormInit && conditioninfo.map(c => {
      let items = [];
      c.items.map(fields => {
        items.push({
          com: (<WeaFormItem
            label={`${fields.label}`}
            labelCol={{span: `${fields.labelcol}`}}
            wrapperCol={{span: `${fields.fieldcol}`}}>
            {/*根据 WeaSwitch 获取对应的组件*/}
            <WeaSwitch fieldConfig={fields} form={form} formParams={formParams}/>
          </WeaFormItem>),
          colSpan: 1
        })
      });
      group.push(<WeaSearchGroup needTigger={true} title={c.title} showGroup={true} items={items}/>)
    });
  }
  return group;
}